Text · React Native 中文网 |
您所在的位置:网站首页 › react 嵌入 android view › Text · React Native 中文网 |
Text 一个用于显示文本的 React 组件,并且它也支持嵌套、样式,以及触摸处理。 在下面的例子里,嵌套的标题和正文文字会继承来自styles.baseText的fontFamily字体样式,不过标题上还附加了它自己额外的样式。标题和文本会在顶部依次堆叠,并且被代码中内嵌的换行符分隔开。 嵌套文本在 iOS 和 Android 中显示格式化文本的方法类似,都是提供你想显示的文本内容,然后使用范围标注来指定一些格式(在 iOS 上是用NSAttributedString,Android 上则是SpannableString)。这种用法非常繁琐。在 React Native 中,我们决定采用和 Web 一致的设计,这样你可以把相同格式的文本嵌套包裹起来: 而实际上在框架内部,这会生成一个扁平结构的NSAttributedString或是SpannableString,包含以下信息: "I am bold and red"0-9: bold9-17: bold, red 容器元素在布局上不同于其它组件:在 Text 内部的元素不再使用 flexbox 布局,而是采用文本布局。这意味着内部的元素不再是一个个矩形,而可能会在行末进行折叠。 First part and second part// Text container: the text will be inline if the space allowed it// |First part and second part|// otherwise, the text will flow as if it was one// |First part |// |and second |// |part | First part and second part// View container: each text is its own block// |First part and|// |second part |// the text will flow in its own block// |First part |// |and |// |second part| 样式继承限制在 Web 上,要想指定整个文档的字体和大小,我们只需要写: /* 这段代码是CSS, *不是*React Native */html { font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px; color: #141823;}当浏览器尝试渲染一个文本节点的时候,它会在树中一路向上查询,直到根节点,来找到一个具备font-size属性的元素。这个系统一个不好的地方在于任何节点都可能会有font-size属性,包括标签。这个 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |